package com.kpiJavaTraining.bogdan.module2;

public class LearnQuestion {
	private Question question;
	private int difficulty;
	private String topic;
	
	//that variable
	private int score;
	private double learningLevel;
	private int countOfAsking;
	private boolean Learned;
	
	public LearnQuestion(){
		this.score=0;
		this.learningLevel=0;
		this.countOfAsking=0;
	}
	
	
	private void update(){
		this.determineLearningLevel();
		this.updateLearned();
	}

	public double getGrasp(){
		this.determineLearningLevel();
		return this.learningLevel;
	}
	
	private void  determineLearningLevel(){
		if(this.countOfAsking!=0){
			this.learningLevel= this.score/(this.countOfAsking*this.difficulty)*100;		
		}
		else this.learningLevel=0;
	}
	public int getCountOfAsking(){
		return this.countOfAsking;
	}
	
	private void  plusCountOfAsking(){
		this.countOfAsking++;
	}

	public int getScore(){
		return this.score;
	}
	
	private void answerCorrectly(){
		this.score+=this.difficulty;
	}
	
	public boolean getLearned(){
		updateLearned();
		return this.Learned;
	}
	
	private void updateLearned(){
		if(this.countOfAsking>=4 && this.learningLevel>70){
			this.Learned=true;
		}
		else this.Learned= false;
	}
		
	public LearnQuestion(Question question){
		this.question=question;
	}
	
	public void setDifficulty(int e){
		this.difficulty=e;
	}
	
	public void setTopic(String topic){
		this.topic=topic;
	}
	
	public Question getQuestion(){
		return this.question;
	}
	
	public int getDifficulty(){
		return this.difficulty;
	}
	
	public String getTopic(){
		return this.topic;
	}
	
	public void answer(String e){
		this.question.answer(e);
		if(this.question.getScore()!=0){
			this.answerCorrectly();
		}
		this.plusCountOfAsking();
		this.update();
	}
	
	public String toString(){
		return this.question.toString();
	}

}
